/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import interfaces.InternationalizableEntity;
import interfaces.InternationalizableEntityDescription;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import javax.faces.context.FacesContext;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "time_availability")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "TimeAvailability.findAll", query = "SELECT t FROM TimeAvailability t"),
    @NamedQuery(name = "TimeAvailability.findByIdTimeAvailability", query = "SELECT t FROM TimeAvailability t WHERE t.idTimeAvailability = :idTimeAvailability"),
    @NamedQuery(name = "TimeAvailability.findByDescription", query = "SELECT t FROM TimeAvailability t WHERE t.description = :description"),
    @NamedQuery(name = "TimeAvailability.findByValue", query = "SELECT t FROM TimeAvailability t WHERE t.value = :value")})
public class TimeAvailability implements Serializable, InternationalizableEntity {
    @OneToMany(mappedBy = "minimumTimeAvailability", fetch = FetchType.LAZY)
    private List<Search> searchList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_TIME_AVAILABILITY")
    private Integer idTimeAvailability;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 40)
    @Column(name = "DESCRIPTION")
    private String description;
    @Basic(optional = false)
    @NotNull
    @Column(name = "VALUE")
    private int value;
    @OneToMany(mappedBy = "timeAvailability", fetch = FetchType.LAZY)
    private List<Candidate> candidateList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "timeAvailability", fetch = FetchType.LAZY)
    private List<TimeAvailabilityDescription> timeAvailabilityDescriptionList;

    public TimeAvailability() {
    }

    public TimeAvailability(Integer idTimeAvailability) {
        this.idTimeAvailability = idTimeAvailability;
    }

    public TimeAvailability(Integer idTimeAvailability, String description, int value) {
        this.idTimeAvailability = idTimeAvailability;
        this.description = description;
        this.value = value;
    }

    public Integer getIdTimeAvailability() {
        return idTimeAvailability;
    }

    public void setIdTimeAvailability(Integer idTimeAvailability) {
        this.idTimeAvailability = idTimeAvailability;
    }

    @Override
    public String getDescription() {
//        String resDescription=description;
//        Locale currentLocale=FacesContext.getCurrentInstance().getViewRoot().getLocale();
//        if(!getTimeAvailabilityDescriptionList().isEmpty() && !currentLocale.equals(Locale.ENGLISH)){
//            String localeCode=currentLocale.getLanguage();
//            for(TimeAvailabilityDescription cd:getTimeAvailabilityDescriptionList()){
//                if(cd.getLanguage().getCode().equals(localeCode)){
//                    resDescription=cd.getDescription();
//                }
//            }
//        }
//        return resDescription;
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    @XmlTransient
    public List<Candidate> getCandidateList() {
        return candidateList;
    }

    public void setCandidateList(List<Candidate> candidateList) {
        this.candidateList = candidateList;
    }

    @XmlTransient
    public List<TimeAvailabilityDescription> getTimeAvailabilityDescriptionList() {
        return timeAvailabilityDescriptionList;
    }

    public void setTimeAvailabilityDescriptionList(List<TimeAvailabilityDescription> timeAvailabilityDescriptionList) {
        this.timeAvailabilityDescriptionList = timeAvailabilityDescriptionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idTimeAvailability != null ? idTimeAvailability.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TimeAvailability)) {
            return false;
        }
        TimeAvailability other = (TimeAvailability) object;
        if ((this.idTimeAvailability == null && other.idTimeAvailability != null) || (this.idTimeAvailability != null && !this.idTimeAvailability.equals(other.idTimeAvailability))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.TimeAvailability[ idTimeAvailability=" + idTimeAvailability + " ]";
    }

    @XmlTransient
    public List<Search> getSearchList() {
        return searchList;
    }

    public void setSearchList(List<Search> searchList) {
        this.searchList = searchList;
    }

    @Override
    public Integer getId() {
        return getIdTimeAvailability();
    }

    @Override
    public List<? extends InternationalizableEntityDescription> getDescriptionsList() {
        return getTimeAvailabilityDescriptionList();
    }
    
}
